import request from '@/api/request.js'

// 发起流程
export function startByProcessKey(id, data) {
  return request({
    url: '../erupt-api/erupt-flow/task/start/' + id,
    method: 'post',
    data: data
  })
}

// 查询实例
export function getProcessInstance(procInstId) {
  return request({
    url: '../erupt-api/erupt-flow/data/OaProcessInstance/' + procInstId,
    method: 'get'
  });
}

// 查询待我处理的工作
export function listMyTasks(params) {
  return request({
    url: '../erupt-api/erupt-flow/task/mine',
    method: 'get',
    params: params
  });
}

// 完成任务
export function completeTask(taskId, remarks, data, sign) {
  return request({
    url: '../erupt-api/erupt-flow/task/complete/' + taskId,
    method: 'post',
    data: {
      remark: remarks,
      data: data,
      sign: sign
    }
  });
}

// 拒绝任务
export function refuseTask(taskId, remarks, data) {
  return request({
    url: '../erupt-api/erupt-flow/task/refuse/' + taskId,
    method: 'post',
    data: {
      remarks: remarks,
      data: data
    }
  });
}

// 预览流程时间线
export function timeLinePreview(processKey) {
  return request({
    url: '../erupt-api/erupt-flow/process/timeline/preview/' + processKey,
    method: 'post'
  });
}

// 查看流程实例的时间线
export function timeLine(taskId) {
  return request({
    url: '../erupt-api/erupt-flow/process/timeline/' + taskId,
    method: 'post'
  });
}

// 查询任务详情
export function getTaskDetail(taskId) {
  return request({
    url: '../erupt-api/erupt-flow/task/detail/' + taskId,
    method: 'get'
  });
}

// 查询实例详情
export function getInstDetail(instId) {
  return request({
    url: '../erupt-api/erupt-flow/inst/detail/' + instId,
    method: 'get'
  });
}

// 查询任务详情
export function getTaskSettingDetail(taskId) {
  return request({
    url: '../erupt-api/erupt-flow/task/setting_detail/' + taskId,
    method: 'get'
  });
}

// 查询实例详情
export function getInstSettingDetail(instId) {
  return request({
    url: '../erupt-api/erupt-flow/inst/setting_detail/' + instId,
    method: 'get'
  });
}

// 查询活动节点数据详情
export function getActivityDataDetail(taskId) {
  return request({
    url: '../erupt-api/erupt-flow/task/activity_detail/' + taskId,
    method: 'get'
  })
}

//保存本次签名
export function saveSign(sign) {
  return request({
    url: '../erupt-api/erupt-flow/sign/save',
    method: 'post',
    data: sign
  })
}

//查找上次签名
export function getSign() {
  return request({
    url: '../erupt-api/erupt-flow/sign/get_sign',
    method: 'get'
  })
}

// 查询与我相关的工单
export function getMineAbout(params) {
  return request({
    url: '../erupt-api/erupt-flow/inst/mine/about',
    method: 'get',
    params: params
  });
}

//储存打印数据
export function savePrintTaskData(taskId,guid,form_html) {
  //编码
  var str = encodeURIComponent(encodeURIComponent(form_html))//编码两次
  return request({
    url: '../erupt-api/erupt-flow/task/print/save/'+taskId+'/'+guid,
    method: 'post',
    data: str
  });
}

//储存打印数据
export function savePrintInstData(instId,guid,form_html) {
  //编码
  var str = encodeURIComponent(encodeURIComponent(form_html))//编码两次
  return request({
    url: '../erupt-api/erupt-flow/inst/print/save/'+instId+'/'+guid,
    method: 'post',
    data: str
  });
}

// 扫码预览流程
export function findFlowPrint(guid) {
  return request({
    url: '../erupt-api/erupt-flow/findFlowPrint/'+guid,
    method: 'get'
  })
}
